package com.literature.threeGroup.controller;

import com.github.pagehelper.Page;
import com.literature.threeGroup.pojo.Organ;
import com.literature.threeGroup.pojo.ResourceInfo;
import com.literature.threeGroup.service.LinXuanService;
import com.literature.threeGroup.util.PageResult;
import com.literature.threeGroup.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName LinXuanController
 * @Description: TODO
 * @Author ForeverLoveT
 * @Date 2020/1/8
 * @Version V1.0
 **/
@RestController
@CrossOrigin
public class LinXuanController {
    @Autowired
    private LinXuanService linXuanService;
    //查询待遴选的状态  为1
    @PostMapping("listdlx/{page}/{size}")
    public PageResult findStatusDselect(@RequestBody ResourceInfo resourceInfo , @PathVariable("page") int page, @PathVariable("size") int size){

        System.err.println(resourceInfo);
        resourceInfo.setDistributionStatus(1);
        Page<ResourceInfo> statusDselect = linXuanService.findStatusDselect(resourceInfo, page, size);
        long total = statusDselect.getTotal();
        List<ResourceInfo> result = statusDselect.getResult();
        return new PageResult(total,result);
    }
    //查询待分配列表
    @PostMapping("listdfp/{page}/{size}")
    public PageResult findStatusDfen(@RequestBody ResourceInfo resource , @PathVariable("page") int page, @PathVariable("size") int size){
        resource.setDistributionStatus(2);
        System.err.println(resource.getType());
        Page<ResourceInfo> statusDselect = linXuanService.findStatusDDfen(resource, page, size);
        long total = statusDselect.getTotal();
        List<ResourceInfo> result = statusDselect.getResult();
        return new PageResult(total,result);
    }
    //查询待确认列表
    @PostMapping("listdqr/{page}/{size}")
    public PageResult findStatusDqueRen(@RequestBody ResourceInfo resourceInfo , @PathVariable("page") int page, @PathVariable("size") int size){
        resourceInfo.setDistributionStatus(3);
        Page<ResourceInfo> statusDselect = linXuanService.findStatusDqueRen(resourceInfo, page, size);
        long total = statusDselect.getTotal();
        List<ResourceInfo> result = statusDselect.getResult();
        return new PageResult(total,result);
    }
    //查询单位
    @GetMapping("finddept")
    public List<Organ> findOrgan(){
        return linXuanService.findOrgan();
    }

    /**
     * @MethodName: Dselect特殊遴选 把待遴选的状态改为待分配
     * @Description: TODO
     * @Param: [id,distributionStatus] 接受一个当前的id 和状态值
     * @Return: com.literature.threeGroup.util.Result
     * @Author: ForeverLoveT;;
     * @Date: 8:24
    **/
    //通用修改状态的方法  批量单条  都可以
    @GetMapping("dselect/{ids}/{distributionStatus}")
    public Result Dselect(@PathVariable("ids")String[] ids, @PathVariable("distributionStatus")int distributionStatus){
            linXuanService.UpdateStatus(ids,distributionStatus);
            return new Result(true,200,"修改成功");
    }

    /**
     * @MethodName: organFenpei  分配单位  修改状态为3
     * @Description: TODO
     * @Param: [ids, id, distributionStatus]ids  是资源id   id是单位id  状态
     * @Return: com.literature.threeGroup.util.Result
     * @Author: ForeverLoveT
     * @Date: 17:11
    **/
    @PostMapping("danwei/{ids}/{id}")
    public Result organFenpei(@PathVariable("ids")String[] ids, @PathVariable("id")String id){
        //本门遴选修改状态
        linXuanService.addOrganToResourcesAndUpdateStatus(ids,id);
        return new Result(true,"分配成功");
    }
    /** 
     * @MethodName: tongYi 同意后生成订单  添加到订单列表  状态改为4
     * @Description: TODO
     * @Param: [ids]
     * @Return: com.literature.threeGroup.util.Result
     * @Author: ForeverLoveT
     * @Date: 18:36
    **/
    @GetMapping("tongyi/{ids}")
    public Result tongYi(@PathVariable("ids")String[] ids){
        linXuanService.tongYi(ids);
        return new Result(true,"同意");
    }
    /**
     * @MethodName: boHui 驳回后写上驳回理由  状态不变
     * @Description: TODO
     * @Param: [ids,note] note 是驳回理由
     * @Return: com.literature.threeGroup.util.Result
     * @Author: ForeverLoveT
     * @Date: 18:38
    **/
    @GetMapping("bohui/{ids}")
    public Result boHui(@PathVariable("ids")String[] ids, @RequestParam("note") String note){
        linXuanService.boHui(ids,note);
        return new Result(true,"驳回成功");
    }
}
